#coding: utf-8
"""
In Famoco we’re proud to work with the best engineer, so our rigorous interview cycle will test your engineering skills.  In order to apply you have to solve the following problem:
You have four colored cubes. Each side of each cube is a single color, and there are four colors: blue (B), red (R), green (G) and yellow (Y) Describing the six faces as front, back, left, right, top, bottom, the cube colors are:
Cube Front Back Left Right Top Bottom
1 R B G Y B Y
2 R G G Y B B
3 Y B R G Y R
4 Y G B R R R
The objective is to find ways to stack the four cubes as a vertical column so that each side of the column is showing all four colors.
In a compiled language of your choice, write a program to find all successful permutations. Please submit the following:
1. Initial estimate of time required for the task
2. Actual time taken for the task
3. Source code of solution
4. DO NOT include any compiled binary code (.exe ) as it could be rejected by mail clients 
"""

class Cube(object):
    def __init__ (self,color_tuple):
        self.front=color_tuple[0]
        self.back=color_tuple[1]
        self.left=color_tuple[2]
        self.right=color_tuple[3]
        self.top=color_tuple[4]
        self.bottom=color_tuple[5]
    def x_rotate (self):
        tmp=self.front
        self.front=self.bottom
        self.bottom=self.back
        self.back=self.top
        self.top=tmp

    def y_rotate (self):
        tmp=self.top
        self.top=self.left
        self.left=self.bottom
        self.bottom=self.right
        self.right=tmp

    def z_rotate (self):
        tmp=self.front
        self.front=self.right
        self.right=self.back
        self.back=self.left
        self.left=tmp

    def start_rotate (self):
        i=0
        while 1:
            yield self
            if i<=3:
                self.y_rotate()
                if i==3:
                    self.z_rotate()
            elif i<=7:
                self.x_rotate()
                if i==7:
                    self.z_rotate()
            elif i<=11:
                self.y_rotate()
                if i==11:
                    self.z_rotate()
            elif i<=15:
                self.x_rotate()
                if i==15:
                    self.y_rotate()
            elif i<=19:
                self.z_rotate()
                if i==19:
                    self.y_rotate()
                    self.y_rotate()
            elif i<=23:
                self.z_rotate()
                if i==24:
                    self.x_rotate()
                    self.x_rotate()
                    self.x_rotate()
            else:
                break
            i+=1

    def __str__ (self):
        return '%s %s %s %s %s %s'%(self.front,self.back,self.left,self.right,self.top,self.bottom)



cube_1=Cube(['R', 'B', 'G', 'Y' ,'B' ,'Y'])
cube_2=Cube(['R', 'G', 'G', 'Y', 'B' ,'B'])
cube_3=Cube(['Y', 'B', 'R', 'G', 'Y', 'R'])
cube_4=Cube(['Y', 'G', 'B', 'R', 'R', 'R'])

def find_a_answer():
    if len(set((cube_1.front,cube_2.front,cube_3.front,cube_4.front)))==4 and \
       len(set((cube_1.back,cube_2.back,cube_3.back,cube_4.back)))==4 and \
       len(set((cube_1.left,cube_2.left,cube_3.left,cube_4.left)))==4 and \
       len(set((cube_1.right,cube_2.right,cube_3.right,cube_4.right)))==4:
        print '1 %s\n2 %s\n3 %s\n4 %s'%(cube_1,cube_2,cube_3,cube_4)
        print '###############################\n'
        global answers
        answers+=1

if __name__=='__main__':
    answers=0
    for cube_1 in cube_1.start_rotate():
        for cube_2 in cube_2.start_rotate():
            for cube_3 in cube_3.start_rotate():
                for cube_4 in cube_4.start_rotate():
                    find_a_answer()


    print 'There are %d answers in total'%answers
